﻿#ifndef WEBSOCKETSERVER_H
#define WEBSOCKETSERVER_H

#include <QObject>
#include <QWebSocketServer>
#include <QtSql>

class websocketserver : public QObject
{
    Q_OBJECT
public:
    explicit websocketserver(quint16 port=33662, QObject *parent = 0);
    virtual ~websocketserver();

    //主动推送 消息 给机器人端
    bool pushMessageToRobot(QString message);
    //发送数据给 机器人端或网页端
    bool sendToClient(QWebSocket* socket, QString message);

private:
    QWebSocketServer *m_websocketServer;
    QWebSocket *m_websocketWebEdit; //网页编辑
    QWebSocket *m_websocketWebWrite; //手写端
    QThread m_thread;
    QString m_szLog;
    void *m_parent;
signals:
    void sigWallRun(int nType, QString strpic);
public slots:
    void onNewConnection();
    void onClosed();
    void textMessageReceived(QString message);
    void disconnectwebsock();

private:
    void parseWebEdit(QWebSocket *socket, QString message);
    void parseWebWrite(QWebSocket *socket, QString message);
};

#endif // WEBSOCKETSERVER_H
